package com.xdap.keymen.service.dayang;

import com.definesys.mpaas.query.MpaasQuery;
import com.xdap.keymen.entity.dayang.DaYangCouponEntity;
import com.xdap.motor.entity.SnowflakeIdWorker;
import com.xdap.runtime.service.RuntimeAppContextService;
import com.xdap.runtime.service.RuntimeDatasourceService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class DaYangCouponService {
    private final RuntimeDatasourceService runtimeDatasourceService;
    private final RuntimeAppContextService runtimeAppContextService;
    private final SnowflakeIdWorker snowflakeIdWorker;

    /**
     * 根据优惠券ID查询优惠券模板详情
     *
     * @param couponId 优惠券ID
     * @return 优惠券模板信息
     */
    public DaYangCouponEntity getCouponDetail(String couponId) {
        String currentTenantId = runtimeAppContextService.getCurrentTenantId();
        MpaasQuery query = runtimeDatasourceService.buildTenantMpaasQuery("xdap_app_" + currentTenantId);
        query.eq("id", couponId);
        return query.doQueryFirst(DaYangCouponEntity.class);
    }
}
